<template>
  <a-spin :spinning="confirmLoading">
    <div>
      <a-form-model ref="form" class="cus-ant-form" :model="model">
        <div style="padding-top: 20px; box-sizing: border-box">
          <a-form-model-item :label="$t('时间')" :labelCol="labelCol" :wrapperCol="wrapperCol" style="margin-bottom: 0">
            <span style="font-size: 16px; color: #000">{{ model.createTime }}</span>
          </a-form-model-item>
          <a-form-model-item v-if="model.type != 1"
            :label="$t('机台名称')"
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            style="margin-bottom: 0"
          >
            <span style="font-size: 16px; font-weight: bold; color: #000">{{ model.gameId_dictText }}</span>
          </a-form-model-item>
          <a-form-model-item v-if="model.type != 1" :label="$t('机号')" :labelCol="labelCol" :wrapperCol="wrapperCol" style="margin-bottom: 0">
            <span style="font-size: 16px; font-weight: bold; color: #f00">{{ model.machineNo }}</span>
          </a-form-model-item>
          <a-form-model-item
            :label="model.type == 1 ? $t('通知内容') : $t('报警内容')"
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            style="margin-bottom: 10px"
          >
            <div v-for="(line, index) in problemLines" :key="index" style="font-size: 16px; font-weight: bold; color: #000">
              {{ line }}
            </div>
          </a-form-model-item>
          <a-form-model-item v-if="model.type != 1" :label="$t('备注信息')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
            <a-textarea v-model="model.remark" rows="3" />
          </a-form-model-item>
        </div>
      </a-form-model>
    </div>
  </a-spin>
</template>

<script>
import { httpAction } from '@/api/manage'

export default {
  name: 'BisDeviceNoticeForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false,
    },
  },
  data() {
    return {
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      url: {
        edit: '/device/bisDeviceNotice/edit',
      },
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
    problemLines() {
      return this.model.problem ? this.model.problem.split('\n') : []
    },
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    edit(record) {
      console.log(record)
      this.model = Object.assign({}, record)
      this.visible = true
    },
    submitForm() {
      let that = this
      that.confirmLoading = true
      let httpurl = ''
      let method = ''
      if (!this.model.id) {
        httpurl += this.url.add
        method = 'post'
      } else {
        httpurl += this.url.edit
        method = 'put'
      }
      httpAction(httpurl, this.model, method)
        .then((res) => {
          if (res.success) {
            that.$message.success(res.message)
            that.$emit('ok')
          } else {
            that.$message.warning(res.message)
          }
        })
        .finally(() => {
          that.confirmLoading = false
        })
    },
  },
}
</script>